package com.mlog.njyjy.ndop.msg.relay.redis;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;


@Slf4j
@Component
public abstract class RedisClientGenerator {

    @Autowired
    private RedisTemplate redisTemplate;

    @Value("${redis.out.time}")
    private String time;

    public void insertStr(String key, String value) {
        redisTemplate.opsForValue().set(key, value);
        redisTemplate.expire(key, Long.parseLong(time), TimeUnit.HOURS);
        log.info("redis insert string done !");
    }
    
    public void insertSet(String key, String value) {
        redisTemplate.opsForSet().add(key, value);
        redisTemplate.expire(key, Long.parseLong(time), TimeUnit.HOURS);
        log.info("redis insert set done !");
    }

    public void insertList(String key, String value) {
        redisTemplate.opsForList().rightPush(key, value);
        redisTemplate.expire(key, Long.parseLong(time), TimeUnit.HOURS);
        System.out.println("-----------------------" + redisTemplate.opsForList().range(key, 0, -1));
        log.info("redis insert list done !");
    }

    public Boolean hasKey(String key) {
        return redisTemplate.hasKey(key);
    }
}
